// Writeing to a file with fstream
// By DreamVB 17:37 02/11/2016

#include <iostream>
#include <fstream>

using namespace std;
using std::cout;
using std::endl;

int main(int argc, char *argv[]){
	char *lzout = "C:\\Test\\tables.txt";
	int i = 1;
	int table = 6;

	//Write 6 times table to the file.
	fstream fs;
	fs.open(lzout,ios::out | ios::binary);

	//Check if file was opened.
	if (!fs){
		cout << "Cannot write to file." << endl;
		exit(1);
	}

	//Write times table.
	while (i <= 12){
		if (i < 10){
			fs << i << "  * " << table << " = " << (i * 6) << endl;
		}
		else{
			fs << i << " * " << table << " = " << (i * 6) << endl;
		}
		i++;
	}

	//Close the file.
	fs.close();

	cout << "File has been created." << endl;

	system("pause");
	return 0;
}